package com.mz.ozy.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.mz.ozy.R;
import com.mz.ozy.bean.GoodsCategoryBean;

import java.util.List;

public class BrandPopGridAdapter extends BaseAdapter {


    private Context mContext;
    private int selectPosition = -1;
    private String id;
    private List<GoodsCategoryBean.CateListBean> mBeanList;

    public BrandPopGridAdapter(Context context, String id, List<GoodsCategoryBean.CateListBean> mBeanList) {
        this.mContext = context;
        this.mBeanList = mBeanList;
        this.id = id;
        if (mBeanList != null && mBeanList.size() > 0) {
            for (int i = 0; i < mBeanList.size(); i++) {
                GoodsCategoryBean.CateListBean cateListBean = mBeanList.get(i);
                if (!TextUtils.isEmpty(this.id) && Integer.parseInt(this.id) == cateListBean.getId()) {
                    selectPosition = i;
                }
            }
        }
    }

    @Override
    public int getCount() {
        return mBeanList.size();
    }

    @Override
    public Object getItem(int position) {
        return mBeanList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_brand_pop_grid, null);
        TextView brandNameTv = view.findViewById(R.id.brandNameTv);
        GoodsCategoryBean.CateListBean bean = mBeanList.get(position);
        brandNameTv.setText(bean.getName());
        if (selectPosition == position) {
            brandNameTv.setTextColor(mContext.getResources().getColor(R.color.white));
            brandNameTv.setBackgroundResource(R.drawable.bg_solid_063eff_2dp);
        } else {
            brandNameTv.setTextColor(mContext.getResources().getColor(R.color.c_8f969e));
            brandNameTv.setBackgroundResource(R.drawable.gray_line_round2);
        }
        return view;
    }

    public void setSelectPosition(int selectPosition) {
        this.selectPosition = selectPosition;
    }
}
